home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 25 user and custom controls / usercontrolsdemo / testpage.aspx.vb < prev    next >
Encoding:
Text File  |  2002-03-19  |  2.5 KB  |  63 lines

  1. Public Class TestPage
  2.     Inherits System.Web.UI.Page
  3.  
  4.     ' the following region contains custom code that defines a pbar
  5.     ' variable and initializes it to point to the PagingBar1 user control,
  6.     ' so that the remainder of the code can reference that object
  7.     ' as if it were a regular ASP.NET control
  8.  
  9. #Region " Web Form Designer Generated Code "
  10.  
  11.     'This call is required by the Web Form Designer.
  12.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  13.  
  14.     End Sub
  15.  
  16.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  17.         'CODEGEN: This method call is required by the Web Form Designer
  18.         'Do not modify it using the code editor.
  19.         InitializeComponent()
  20.         ' get a reference to the PagingBar1 user control
  21.         pbar = DirectCast(FindControl("PagingBar1"), PagingBar)
  22.     End Sub
  23.     Protected WithEvents txtPages As System.Web.UI.WebControls.TextBox
  24.     Protected WithEvents btnUpdate As System.Web.UI.WebControls.Button
  25.     Protected WithEvents PlaceHolder1 As System.Web.UI.WebControls.PlaceHolder
  26.     Protected WithEvents chkShowControl As System.Web.UI.WebControls.CheckBox
  27.     Protected WithEvents lblPageData As System.Web.UI.WebControls.Label
  28.     ' this variable retrieves a reference to the PaginBar control
  29.     Protected WithEvents pbar As PagingBar
  30.  
  31. #End Region
  32.  
  33.     Protected WithEvents pbar2 As PagingBar
  34.  
  35.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  36.         ' Initialize the page count the first time the page is shown
  37.         If Not Me.IsPostBack Then
  38.             pbar.PageCount = 50
  39.             txtPages.Text = pbar.PageCount.ToString
  40.         End If
  41.  
  42.         ' dinamically create a new PagingBar control if the checkbox
  43.         ' is selected
  44.         If chkShowControl.Checked Then
  45.             pbar2 = DirectCast(LoadControl("PagingBar.ascx"), PagingBar)
  46.             PlaceHolder1.Controls.Add(pbar2)
  47.             pbar2.PageCount = 99
  48.         End If
  49.     End Sub
  50.  
  51.     ' handling event from the user control
  52.  
  53.     Private Sub pbar_PageChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles pbar.PageChanged
  54.         lblPageData.Text = "( showing page #" & pbar.PageNumber & ")"
  55.     End Sub
  56.  
  57.     ' enforce a different number of pages for the PagingBar control
  58.  
  59.     Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
  60.         pbar.PageCount = CInt(txtPages.Text)
  61.     End Sub
  62. End Class
  63.